//
//  AddPondModel.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/7/22.
//

#import "AddPondModel.h"

@implementation AddPondModel

+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{
        @"addPondModelList":[addPondModelListModel class],
        @"stepModelList":[TemplateFoundDetailsStepModelListModel class],
    };
}
- (NSMutableArray<addPondModelListModel *> *)addPondModelList{
    if(!_addPondModelList){
        _addPondModelList = [NSMutableArray array];
    }
    return _addPondModelList;
}
-(NSMutableArray<TemplateFoundDetailsStepModelListModel *> *)stepModelList{
    if(!_stepModelList){
        _stepModelList = [NSMutableArray array];
    }
    return _stepModelList;
}
-(NSMutableArray <NSString *>*)pictureImgArray {
    if(!_pictureImgArray){
        if(self.pictureImg.length > 0){
            _pictureImgArray = [NSMutableArray arrayWithArray: [self.pictureImg componentsSeparatedByString:@","]];
        } else {
            _pictureImgArray = [NSMutableArray array];
        }
    }
    return _pictureImgArray;
}
- (NSMutableArray<NSString *> *)TJpictureImgArray{
    if(!_TJpictureImgArray){
        if(self.TJpictureImgStr.length > 0){
            _TJpictureImgArray = [NSMutableArray arrayWithArray: [self.TJpictureImgStr componentsSeparatedByString:@","]];
        } else {
            _TJpictureImgArray = [NSMutableArray array];
        }
    }
    return _TJpictureImgArray;
}
- (NSString *)TJpictureImgStr{
    if(!_TJpictureImgStr){
        if(_TJpictureImgArray.count > 0){
            _TJpictureImgStr = [_TJpictureImgArray componentsJoinedByString:@","];
        } else {
            _TJpictureImgStr = @"";
        }
    }
    return _TJpictureImgStr;
}
-(NSString *)pictureImgStr{
    if(!_pictureImgStr){
        if(self.pictureImgArray.count > 0){
            _pictureImgStr = [self.pictureImgArray componentsJoinedByString:@","];
        } else {
            _pictureImgStr = @"";
        }
    }
    return _pictureImgStr;
}

-(BOOL)isYSL{
    return [self.addPondModelList.firstObject.typeName isEqualToString:@"衍生类"];
}


-(BOOL)isLastModel{
    return self.stepModelList.lastObject.isSeled;
}

///选中另一个步骤
- (void)setSeledModel:(TemplateFoundDetailsStepModelListModel *)model{
    for (TemplateFoundDetailsStepModelListModel * smodel in self.stepModelList) {
        smodel.isSeled = NO;
    }
    model.isSeled = YES;
}
- (TemplateFoundDetailsStepModelListModel *)seledModel{
    for (TemplateFoundDetailsStepModelListModel * smodel in self.stepModelList) {
        if(smodel.isSeled){
            return smodel;
        }
    }
    self.stepModelList.firstObject.isSeled = YES;
    return self.stepModelList.firstObject;
}
///提交时的提示文本
- (NSString *)TjAPiHUDString{
    ///只判断任务就可以了
    for (TemplateFoundDetailsStepModelListModel * StepModel in self.stepModelList) {
        if([StepModel TjAPiHUDString].length > 0){
            return [StepModel TjAPiHUDString];
        }
        for (TemplateFoundDetailsTaskTypeModelListModel * typeModel in StepModel.taskTypeModelList) {
            if(typeModel.taskType == 1){//自定义可以不填人
                if( typeModel.appointorArray.count < 1){
                    return [NSString stringWithFormat:@"请选择%@的任务指派人",typeModel.name];
                }
            }
        }
    }
    return @"";
}
///提交字典
- (NSMutableDictionary *) TjDict{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    [dict setObject:@([self.area intValue]) forKey:@"area"];
    [dict setObject:@(self.batchFlag) forKey:@"batchFlag"];
    if([self.breedCycle intValue] > 0){
        [dict setObject:@([self.breedCycle intValue]) forKey:@"breedCycle"];
    }
    [dict setObject:self.breedTypeId forKey:@"breedTypeId"];
    [dict setObject:self.directorName forKey:@"directorName"];
    [dict setObject:self.directorPhone forKey:@"directorPhone"];
    [dict setObject:self.executeDate forKey:@"executeDate"];
    [dict setObject:[self.TJpictureImgArray componentsJoinedByString:@","] forKey:@"pictureImg"];
    [dict setObject:self.templateId forKey:@"templateId"];
    if(self.templateVersionNumber.length > 0){
        [dict setObject:@([self.templateVersionNumber intValue]) forKey:@"templateVersionNumber"];
    }
    
    [dict setObject:self.typeId forKey:@"typeId"];
    NSMutableArray * addPondModelList = [NSMutableArray array];
    for (addPondModelListModel * listmodel in self.addPondModelList) {
        [addPondModelList addObject:[listmodel TjDict]];
    }
    [dict setObject:addPondModelList forKey:@"addPondModelList"];

    NSMutableArray * stepModelList = [NSMutableArray array];
    for (TemplateFoundDetailsStepModelListModel * model in self.stepModelList) {
        [stepModelList addObject:[model TjDictWithNew:(model.templateStepId.length == 0)]];
    }
    [dict setObject:stepModelList forKey:@"stepModelList"];

    return dict;
}



- (void)encodeWithCoder:(NSCoder *)coder{
    [coder encodeObject:self.area forKey:@"area"];
    [coder encodeInteger:self.batchFlag forKey:@"batchFlag"];
    
    [coder encodeObject:self.templateType forKey:@"templateType"];
    [coder encodeObject:self.breedCycle forKey:@"breedCycle"];
    [coder encodeObject:self.breedTypeId forKey:@"breedTypeId"];
    [coder encodeObject:self.breedTypeName forKey:@"breedTypeName"];
    [coder encodeObject:self.directorName forKey:@"directorName"];
    [coder encodeObject:self.directorPhone forKey:@"directorPhone"];
    [coder encodeObject:self.executeDate forKey:@"executeDate"];
    [coder encodeObject:self.orgCode forKey:@"orgCode"];
    ///相册字符串
    [coder encodeObject:self.TJpictureImgStr forKey:@"TJpictureImgStr"];
    [coder encodeObject:self.pictureImg forKey:@"pictureImg"];
    [coder encodeObject:self.pictureImgStr forKey:@"pictureImg"];
    [coder encodeObject:self.templateId forKey:@"templateId"];
    [coder encodeObject:self.templateVersionNumber forKey:@"templateVersionNumber"];
    [coder encodeObject:self.templateName forKey:@"templateName"];
    [coder encodeObject:self.typeId forKey:@"typeId"];
    [coder encodeObject:self.typeName forKey:@"typeName"];
    [coder encodeObject:self.addPondModelList forKey:@"addPondModelList"];
    
    
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    if (self = [super init]) {
        self.area = [coder decodeObjectForKey:@"area"];
        self.batchFlag = [coder decodeIntegerForKey:@"batchFlag"];
        self.templateType = [coder decodeObjectForKey:@"templateType"];
        self.breedCycle = [coder decodeObjectForKey:@"breedCycle"];
        self.breedTypeId = [coder decodeObjectForKey:@"breedTypeId"];
        self.breedTypeName = [coder decodeObjectForKey:@"breedTypeName"];
        self.directorName = [coder decodeObjectForKey:@"directorName"];
        self.directorPhone = [coder decodeObjectForKey:@"directorPhone"];
        self.executeDate = [coder decodeObjectForKey:@"executeDate"];
        self.orgCode = [coder decodeObjectForKey:@"orgCode"];
        self.pictureImg = [coder decodeObjectForKey:@"pictureImg"];
        self.pictureImgStr = [coder decodeObjectForKey:@"pictureImgStr"];
        self.TJpictureImgStr = [coder decodeObjectForKey:@"TJpictureImgStr"];
        self.templateId = [coder decodeObjectForKey:@"templateId"];
        self.templateVersionNumber = [coder decodeObjectForKey:@"templateVersionNumber"];
        self.templateName = [coder decodeObjectForKey:@"templateName"];
        self.typeId = [coder decodeObjectForKey:@"typeId"];
        self.typeName = [coder decodeObjectForKey:@"typeName"];
        self.addPondModelList = [coder decodeObjectForKey:@"addPondModelList"];
        
        
    
    }
    return self;
}



@end


@implementation addPondModelListModel


+ (NSDictionary *)modelCustomPropertyMapper {
    return @{
             @"tissueName":@[@"tissue",@"tissueName"],
           
    };
}
///提交时的提示文本
- (NSString *)TjAPiHUDString{
    return @"";
}
///提交字典
- (NSMutableDictionary *)TjDict{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    if(self.expectYield.length > 0){
        [dict setObject:@([self.expectYield intValue]) forKey:@"expectYield"];
    }
    [dict setObject:self.name forKey:@"name"];
    [dict setObject:self.tissueId forKey:@"tissueId"];
    return dict;

}



- (void)encodeWithCoder:(NSCoder *)coder{
    [coder encodeObject:self.expectYield forKey:@"expectYield"];
    [coder encodeObject:self.name forKey:@"name"];
    [coder encodeObject:self.tissueId forKey:@"tissueId"];
    [coder encodeObject:self.tissueName forKey:@"tissueName"];
    [coder encodeObject:self.typeName forKey:@"typeName"];

    
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    if (self = [super init]) {
        self.expectYield = [coder decodeObjectForKey:@"expectYield"];
        self.name = [coder decodeObjectForKey:@"name"];
        self.tissueId = [coder decodeObjectForKey:@"tissueId"];
        self.tissueName = [coder decodeObjectForKey:@"tissueName"];
        self.typeName = [coder decodeObjectForKey:@"typeName"];

    }
    return self;
}

@end

@implementation pondTypeModel

+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"ID":@[@"id"],
    };
}

@end

@implementation AddXGPondModel


+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"ID":@[@"id"],
             @"templateName":@[@"template"],
             @"tissueName":@[@"tissue"],
             @"typeName":@[@"type"],
             @"breedTypeName":@[@"breedType"]
    };
}
//- (NSMutableArray<NSString *> *)XGpictureImgArray{
//    if(!_XGpictureImgArray){
//        if(self.pictureImgUrl.length > 0){
//            _XGpictureImgArray = [NSMutableArray arrayWithArray: [self.pictureImgUrl componentsSeparatedByString:@","]];
//        } else {
//            _XGpictureImgArray = [NSMutableArray array];
//        }
//        self.TJpictureImgArray = _XGpictureImgArray;
//    }
//    return _XGpictureImgArray;
//}

-(CGFloat)XGHeaderViewH{
    if(self.isNext){///下一步后
        return 0;
    }
//    if(self.typeCode == 0 || self.addPondModelList.count < 1){
    if(self.addPondModelList.count < 1){
        return kwt(180);
    } else {
        return kwt(240);
    }
}
- (CGFloat)XGFooterViewH{
    if(self.isNext){///下一步后
        return kwt(482 + 120);
    } else {
        if(self.isAll){
            return 0;
        } else {
            if(self.typeCode == 0 && self.typeName.length > 0){///衍生类
                return kwt(482);
            } else {
                return kwt(482 + 180);
            }
        }
    }
   
}
- (CGFloat)XGCellH{
    if(self.isNext == NO){
        if(self.isAll && self.isGroup){
            return kwt(135 + 65) + kwt(40 * self.addPondModelList.count);
        }
    }
    return 0;
}
///提交时的提示文本
- (NSString *)XGTjAPiHUDString{
   
    ///只判断任务就可以了
    for (TemplateFoundDetailsStepModelListModel * StepModel in self.stepModelList) {
        if([StepModel TjAPiHUDString].length > 0){
            return [StepModel TjAPiHUDString];
        }
        for (TemplateFoundDetailsTaskTypeModelListModel * typeModel in StepModel.taskTypeModelList) {
            if(typeModel.taskType == 1){//自定义可以不填人
                if( typeModel.appointorArray.count < 1){
                    return [NSString stringWithFormat:@"请选择%@的任务指派人",typeModel.name];
                }
            }
        }
    }
    return @"";
}
///提交字典
- (NSMutableDictionary *) XGTjDict{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    [dict setObject:@([self.area intValue]) forKey:@"area"];
    [dict setObject:@(self.batchFlag) forKey:@"batchFlag"];
    if([self.breedCycle intValue] > 0){
        [dict setObject:@([self.breedCycle intValue]) forKey:@"breedCycle"];
    }

    [dict setObject:self.breedTypeId forKey:@"breedTypeId"];
    [dict setObject:self.directorName forKey:@"directorName"];
    [dict setObject:self.directorPhone forKey:@"directorPhone"];
    [dict setObject:self.executeDate forKey:@"executeDate"];
    [dict setObject:self.ID forKey:@"id"];
    [dict setObject:@(self.ifReselectTemplate) forKey:@"ifReselectTemplate"];
    [dict setObject:self.name forKey:@"name"];
    [dict setObject:self.expectYield forKey:@"expectYield"];
    
    [dict setObject:[self.TJpictureImgArray componentsJoinedByString:@","] forKey:@"pictureImg"];
    [dict setObject:self.templateId forKey:@"templateId"];
    if(self.templateVersionNumber.length > 0){
        [dict setObject:@([self.templateVersionNumber intValue]) forKey:@"templateVersionNumber"];
    }
    [dict setObject:self.tissueId forKey:@"tissueId"];
    [dict setObject:self.typeId forKey:@"typeId"];
    NSMutableArray * addPondModelList = [NSMutableArray array];
    for (addPondModelListModel * listmodel in self.addPondModelList) {
        [addPondModelList addObject:[listmodel TjDict]];
    }
    [dict setObject:addPondModelList forKey:@"addPondModelList"];

    NSMutableArray * stepModelList = [NSMutableArray array];
    for (TemplateFoundDetailsStepModelListModel * model in self.stepModelList) {
//        [stepModelList addObject:[model TjDictWithNew:(model.templateStepId.length == 0)]];
        [stepModelList addObject:[model TjDictWithXG:(model.templateStepId.length == 0)]];
    }
    [dict setObject:stepModelList forKey:@"stepModelList"];

    return dict;
}
@end
